package com.ruoyi.project.remake.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.remake.domain.ApplyDocument;
import com.ruoyi.project.remake.service.IApplyDocumentService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 申请单据Controller
 * 
 * @author 孙山伟
 * @date 2023-03-28
 */
@RestController
@RequestMapping("/remake/document")
public class ApplyDocumentController extends BaseController
{
    @Autowired
    private IApplyDocumentService applyDocumentService;

    /**
     * 查询申请单据列表
     */
    @PreAuthorize("@ss.hasPermi('remake:document:list')")
    @GetMapping("/list")
    public TableDataInfo list(ApplyDocument applyDocument)
    {
        startPage();
        List<ApplyDocument> list = applyDocumentService.selectApplyDocumentList(applyDocument);
        return getDataTable(list);
    }

    /**
     * 导出申请单据列表
     */
    @PreAuthorize("@ss.hasPermi('remake:document:export')")
    @Log(title = "申请单据", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(ApplyDocument applyDocument)
    {
        List<ApplyDocument> list = applyDocumentService.selectApplyDocumentList(applyDocument);
        ExcelUtil<ApplyDocument> util = new ExcelUtil<ApplyDocument>(ApplyDocument.class);
        return util.exportExcel(list, "document");
    }

    /**
     * 获取申请单据详细信息
     */
    @PreAuthorize("@ss.hasPermi('remake:document:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(applyDocumentService.selectApplyDocumentById(id));
    }

    /**
     * 新增申请单据
     */
    @PreAuthorize("@ss.hasPermi('remake:document:add')")
    @Log(title = "申请单据", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ApplyDocument applyDocument)
    {
        return toAjax(applyDocumentService.insertApplyDocument(applyDocument));
    }

    /**
     * 修改申请单据
     */
    @PreAuthorize("@ss.hasPermi('remake:document:edit')")
    @Log(title = "申请单据", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ApplyDocument applyDocument)
    {
        return toAjax(applyDocumentService.updateApplyDocument(applyDocument));
    }

    /**
     * 删除申请单据
     */
    @PreAuthorize("@ss.hasPermi('remake:document:remove')")
    @Log(title = "申请单据", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(applyDocumentService.deleteApplyDocumentByIds(ids));
    }
}
